<template>
  <view class="title-container">
    <!-- 标题栏 -->
    <view class="title-header">
      <!-- 展开时显示完整标题，收起时显示省略号 -->
      <text :class="['title-text', { expanded: isExpanded }]">{{ videoAbout.videoName }}</text>
      <image
        class="toggle-icon"
        :class="{ rotated: isExpanded }"
        src="/static/alibaba_icon/down.svg"
        @click="toggleExpand"
      />
    </view>

    <!-- 展开的内容，使用 transition 过渡效果 -->
    <transition name="expand">
      <view v-show="isExpanded" class="expanded-content">
        <text class="video-id">DV{{ videoAbout.videoId }}</text>
        <br />
        <text class="video-remake">{{ videoAbout.videoRemake }}</text>
      </view>
    </transition>
  </view>
</template>

<script>
import { mapState } from 'vuex';

export default {
  data() {
    return {
      isExpanded: false,
      videoAbout: {} // 用于存储深复制的数据
    };
  },
  created() {
    // 在组件创建时进行深复制
    this.videoAbout = JSON.parse(JSON.stringify(this.$store.state.videoAbout));
  },
  methods: {
    toggleExpand() {
      this.isExpanded = !this.isExpanded;
    }
  }
};
</script>

<style scoped>
.title-container {
  padding: 10px;
  border-radius: 5px;
  background-color: #fff;
}

.title-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.title-text {
  font-size: 16px;
  font-weight: bold;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: all 0.3s ease;
}

.title-text.expanded {
  white-space: normal; /* 允许换行显示 */
  overflow: visible;
  text-overflow: clip;
}

.expanded-content {
  padding-top: 10px;
  font-size: 14px;
  color: #707070;
}

.video-id {
  color: #707070;
  font-size: 10px;
  font-weight: bold;
}

.video-remake {
  font-size: 10px;
  color: #999;
}

.toggle-icon {
  width: 16px;
  height: 16px;
  transition: transform 0.5s ease; /* 旋转动画时长为0.5秒 */
}

.rotated {
  transform: rotate(180deg);
}

/* 展开动画 */
.expand-enter-active,
.expand-leave-active {
  transition: max-height 0.5s ease, opacity 0.5s ease;
}

.expand-enter,
.expand-leave-to {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
}

.expand-enter-to {
  max-height: 500px; /* 设置一个较大的值以确保内容完全展开 */
  opacity: 1;
}
</style>
